<?php
	
	//$arr = array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5);

	//echo json_encode($arr);
	

	//print $_GET['result___'];
	
	$file_real = $_REQUEST['result___'];
	
	if( !empty($_REQUEST['download']) ){
		
		//if($_REQUEST['download']=="0"){
			
		//}else{
			
			//$file_name=$_REQUEST['key'].".".$_REQUEST['notation'];
			
			header('Pragma: public'); 	// required
			header('Expires: 0');		// no cache
			header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
			header('Last-Modified: '.gmdate ('D, d M Y H:i:s', filemtime($file_real)).' GMT');
			header('Cache-Control: private',false);
			header('Content-Type: application/force-download');
			header('Content-Description: File Transfer');
			//header('Content-Type: application/force-download');

			switch($_REQUEST['notation']){
				case 'csv':
						header('Content-type: text/csv');
						header('Content-type: application/csv');
					break;
				case 'json':
						header('Content-type: text/json');
						header('Content-type: application/json');
					break;
				default:
					
				
			}
			
			
			header('Content-Disposition: attachment; filename="'.basename($file_real).'"');
			header('Content-Transfer-Encoding: binary');
			header('Content-Length: '.filesize($file_real));	// provide file size
			header('Connection: close');
		
		//}
	}

	//ini_set('zlib.output_compression', 'Off');

	//header('Content-Disposition: attachment; filename='.basename($file_real));
	//header('Content-Length: ' . filesize($file));
	
	if(file_exists($file_real)){
		
		ob_clean();
    	flush();
		//readfile($file_real);

		//$url	=	"http://".$_SERVER['HTTP_HOST']."/api/apiopengovernmentdata/download/".basename($file_real);
	
		//header('Location: '.$url);
	
		//passthru($file_real);
		$handle = fopen($file_real, "rb");
		//while (!feof($handle)){
		    //I would suggest to do some checking
		    //to see if the user is still downloading or if they closed the connection
		//    echo fread($handle, 8192);
		//}
		fpassthru($handle);
		fclose($handle);


		
	}
	
?>